package cn.sh.yhk.configure.security;

import cn.sh.yhk.vo.BasicVo;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IDEA
 * author:Yhk
 * Date:2019/1/9
 * Time:4:09 PM
 */
@Component
public class AjaxAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, org.springframework.security.access.AccessDeniedException e) throws IOException, ServletException {
        httpServletResponse.getWriter().write(JSONObject.toJSONString(BasicVo.fail("Need Authorities!")));
    }
}